package frame.exec 
{
	import config.APPSIZE;
	import config.COLORCONFIG;
	import config.FRAME_EXEC;
	import data.DataMonitor;
	import debug.ASSERT;
	import fl.motion.easing.Back;
	import fl.transitions.Tween;
	import fl.transitions.TweenEvent;
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.text.TextFormatAlign;
	import flash.utils.Dictionary;
	import frame.IFrame;
	import nsdecl.ns_bindattr_filter;
	import nsdecl.ns_dialog_service;
	import nsdecl.ns_event_listener;
	import nsdecl.ns_extern_reqcall;
	import nsdecl.ns_fileurl_const;
	import nsdecl.ns_group_handler;
	import nsdecl.ns_interactive_slot;
	import nsdecl.ns_vname_decl;
	import common.StructTime;
	import mx.utils.StringUtil;
	import ui.ui_button;
	import ui.ui_combo_box;
	import ui.ui_text;
	import ui.uiGroup;
	import ui.uiUnit;
	import ui.uiWin;
	import ui.utils.attrControl;
	import ui.utils.bindattrFormat;
	import ui.utils.initUIContainer;
	import ui.utils.setPosUnit;
	import utils.range;
	import vndecl.*;
	
	/**
	 * 开始排班的集合
	 * @author anod
	 */
	public class ExecPage extends uiWin implements IFrame
	{
		use namespace ns_interactive_slot;
		use namespace ns_event_listener;
		use namespace ns_extern_reqcall;
		use namespace ns_vname_decl;
		
		private static const PANEL_TOTAL_COUNT:int = 5;
		
		private var mTitle:FExecTitle;				//标题标签
		private var mPanel:Sprite;					//称赞面板
		private var mPanelIndex:int;				//当前进度
		private var mPanelTween:Tween;				//面板切换动画
		
		public function ExecPage() 
		{
			mPanelIndex = 0;
			
			var panel_in_ui:FExecSetting = new FExecSetting();
			var set_range:SetDateRange = new SetDateRange( panel_in_ui.mSetExecDate );
			var set_timeseg:SetTimesegDate = new SetTimesegDate( panel_in_ui.mSetExecTime );
			var set_group:SetGroupAssignment = new SetGroupAssignment( panel_in_ui.mSetExecGroup );
			var set_staff:SetStaffSchedule = new SetStaffSchedule( panel_in_ui.mSetExecStaff );
			
			mPanel = new Sprite();
			mPanel.addChild( set_range );
			mPanel.addChild( set_timeseg );
			mPanel.addChild( set_group );
			mPanel.addChild( set_staff );
			addChild( mPanel );
			
			mPanelTween = new Tween(new Object, "x", Back.easeOut, 0, 0, 0.6, true);
			mPanelTween.stop();
			mPanelTween.addEventListener( TweenEvent.MOTION_CHANGE, useInteger );
			mPanelTween.addEventListener( TweenEvent.MOTION_FINISH, resetTween );
			
			mTitle = new FExecTitle();
			mTitle.gotoAndStop(0);
			addChild( mTitle );
			
			setupInteractive();
			setupDataMonitor();
		}
		
		/* INTERFACE frame.IFrame */
		
		public function setupInteractive():void 
		{

		}
		
		public function setupDataMonitor():void 
		{

		}
		
		// 主体功能
		//-----------------------------------------------
		/** 选中某一个面板 */
		ns_extern_reqcall function selectPanel( panel_index:int ):void
		{
			ASSERT( panel_index >= 0 );
			ASSERT( panel_index < PANEL_TOTAL_COUNT );
			
			mPanelIndex = panel_index;
			var px:int = panel_index * APPSIZE.width;
			mPanelTween.begin = mPanel.x;
			mPanelTween.finish = -px;
			mPanelTween.start();
		}
		
		ns_dialog_service function listWeek( entry:uiUnit, month_info:Point ):void
		{
			var backg:UDateMonth = new UDateMonth();
			var day:Date = new Date();
			day.setTime( month_info.x );
			backg.panel.component.text = String( day.month + 1 );
			
			var calendar:uiGroup = new uiGroup();
			calendar.setRule( new setPosUnit( 6, 7, 26, 17 ) );
			calendar.child = uiUnit;
			calendar.data = VNIC.EXEC_WEEKDATA + "." + entry.key;
			calendar.handler = "listWeekday";
			calendar.y = backg.panel.y;
			calendar.width = backg.panel.width;
			calendar.height = backg.panel.height;
			
			initUIContainer( backg );
			entry.addChild( backg );
			entry.addChild( calendar );
		}
		
		ns_dialog_service function listWeekday( entry:uiUnit, day_info:int ):void
		{
			var txt:ui_text = new ui_text();
			txt.width = 20;
			txt.height = 16;
			txt.x = 2;
			txt.y = 2;
			txt.align = TextFormatAlign.CENTER;
			txt.bold = true;
			txt.letterspace = 0;
			txt.stroke = 0x4f4f4f;
			txt.text = String( day_info );
			
			entry.addChild( txt );
			
			var offset:int = DataMonitor.getData( entry.owner.data + "." + "offset" );
			var correct:int = day_info + offset - 1;
			txt.color = ( ( correct + 1 ) % 7 ) < 2 ? COLORCONFIG.Q_ORANGE : COLORCONFIG.Q_GRAY;
			entry.owner.getRule().setPosition( entry, correct );
		}
		
		// UI回调
		//----------------------------------------------
		/** 设置进度标题于当前帧 */
		ns_event_listener function resetTween( e:TweenEvent ):void
		{
			mTitle.gotoAndStop( mPanelIndex + 1 );
			mPanel.x = mPanelTween.finish;
		}
		ns_event_listener function useInteger( e:TweenEvent ):void
		{
			var value:Number = e.position;
			mPanel.x = Math.round( value );
		}
		/** 下一页 */
		ns_interactive_slot function nextPanel( button:ui_button ):void
		{
			selectPanel( mPanelIndex + 1 );
		}
		/** 上一页 */
		ns_interactive_slot function prevPanel( button:ui_button ):void
		{
			selectPanel( mPanelIndex - 1 );
		}
	}

}